package com.acme.bankapp.domain;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Categories.ExcludeCategory;

import com.acme.bankapp.domain.Bank;
import com.acme.bankapp.domain.Client;
import com.acme.bankapp.domain.Gender;
import com.acme.bankapp.domain.accounts.Account;
import com.acme.bankapp.domain.accounts.SavingsAccount;
import com.acme.bankapp.exceptions.ClientExistsException;
import com.acme.bankapp.service.ClientService.PrintClientListener;
import com.acme.bankapp.service.listeners.ClientRegistrationListener;

import org.mockito.Mockito;
import org.mockito.Mockito.*;

import static org.mockito.Mockito.*;

public class AddClientToBankCase {

	private Bank bank;

	@Before
	public void init() {
	}
	
	@Test(expected = ClientExistsException.class)
	public void shouldThrowExceptionWhenClientExists() throws ClientExistsException {
		//Given
		//See init()
		bank = new Bank();
		bank.addClient(new Client("Vassiliy Pupkine", Gender.MALE), new SavingsAccount());
		
		//When
		bank.addClient(new Client("Vassiliy Pupkine", Gender.MALE), new SavingsAccount());		
		
		//Then
		// see "expected"
	}
	
	@Test 
	public void shouldNotifyListenersWhenClientExists() throws ClientExistsException {
		//Given
		//See init()
		bank = new Bank();
		ClientRegistrationListener listener = mock(ClientRegistrationListener.class);
		bank.addClientRegistrationListener(listener);
		
		Client client = mock(Client.class);
		when(client.getName()).thenReturn("Vassiliy Pupkine");
		Account account = mock(Account.class);
		bank.addClient(client, account);
		
		//When
		Client client1 = mock(Client.class);
		when(client1.getName()).thenReturn("Vassiliy Pupkine");
		
		try { 
			bank.addClient(client1, account);		
		} catch (ClientExistsException e) {
			System.out.println("[TEST DEBUG] ClientExistsException");
		}

		//Then
		verify(listener, times(1)).onClientNotAdded(anyString());
	}

}
